package com.springboot.repository;

import com.springboot.domain.BtDemand;
import com.springboot.domain.BtTeam;
import com.springboot.dto.TeamInfoDTO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TeamRepository extends JpaRepository<BtTeam, String>{

    BtTeam findByUserIdAndDemand(String userId, BtDemand demand);

    @Modifying
    @Query("delete from BtTeam bt where bt.role = false and bt.demand = ?1")
    void deleteMembersByDemandId(BtDemand demand);

    List<BtTeam> findByDemandId(String id);

    @Query("select new com.springboot.dto.TeamInfoDTO(bt.userId, bt.role, bu.userName) from BtTeam bt, BtUser bu where bt.userId = bu.userId and bt.demand = ?1")
    List<TeamInfoDTO> findTeamByDemandId(BtDemand btDemand);

}
